package com.controller;

import com.pojo.Collections;
import com.pojo.Result;
import com.service.CollectionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/collections")
public class CollectionsController {

    @Autowired
    private CollectionsService collectionsService;

    @PostMapping
    public Result<Void> collectNote(
            @RequestParam Integer userId,
            @RequestParam Integer noteId) {
        return collectionsService.collectNote(userId, noteId);
    }

    @DeleteMapping
    public Result<Void> uncollectNote(
            @RequestParam Integer userId,
            @RequestParam Integer noteId) {
        return collectionsService.uncollectNote(userId, noteId);
    }

    @DeleteMapping("/user/{userId}")
    public Result<Void> uncollectAllByUserId(@PathVariable Integer userId) {
        return collectionsService.uncollectAllByUserId(userId);
    }

    @DeleteMapping("/note/{noteId}")
    public Result<Void> uncollectAllByNoteId(@PathVariable Integer noteId) {
        return collectionsService.uncollectAllByNoteId(noteId);
    }

    @GetMapping("/status")
    public Result<Boolean> isCollected(
            @RequestParam Integer userId,
            @RequestParam Integer noteId) {
        return collectionsService.isCollected(userId, noteId);
    }

    @GetMapping("/note/{noteId}/count")
    public Result<Integer> getCollectionCountByNoteId(@PathVariable Integer noteId) {
        return collectionsService.getCollectionCountByNoteId(noteId);
    }

    @GetMapping("/user/{userId}/count")
    public Result<Integer> getCollectionCountByUserId(@PathVariable Integer userId) {
        return collectionsService.getCollectionCountByUserId(userId);
    }

    @GetMapping("/user/{userId}")
    public Result<List<Collections>> getCollectionsByUserId(@PathVariable Integer userId) {
        return collectionsService.getCollectionsByUserId(userId);
    }

    @GetMapping("/note/{noteId}")
    public Result<List<Collections>> getCollectionsByNoteId(@PathVariable Integer noteId) {
        return collectionsService.getCollectionsByNoteId(noteId);
    }
}